package com.licheng.aop;

import com.licheng.mapper.EmpMapper;
import com.licheng.pojo.Result;
import com.licheng.utils.JwtUtils;
import io.jsonwebtoken.Claims;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
//@Aspect
public class ReportAllow {
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private HttpServletResponse response;
    @Autowired
    private EmpMapper empMapper;

    @Around("execution(* com.licheng.controller.ReportController.*(..))")
    public Object recordTimeAop(ProceedingJoinPoint pjp) throws Throwable {
        //获取用户id
        String token = request.getHeader("token");
        Claims claims = JwtUtils.parseJWT(token);
        Integer operate_emp_id = (Integer) claims.get("id");

        //查询员工是第几个用户
        Integer integer = empMapper.selectIdCount(operate_emp_id);
        //判断
        if (integer >= 10) {
            return Result.error("对不起你没权限");
        }
        Object proceed = pjp.proceed();
        return proceed;
    }
}
